package mhwi.powers;

import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.powers.AbstractPower;
import mhwi.helper.ModHelper;

import static mhwi.constants.ResourcesConstant.EXTENSION_PNG;
import static mhwi.constants.ResourcesConstant.PATH_IMG_POWERS;

public class TemplatePower extends AbstractPower {
    protected final String[] DESCRIPTIONS;
    public final String POWER_ID;

    public TemplatePower(AbstractCreature owner, int amount, Class<? extends TemplatePower> PowerClass) {
        String CLASS_NAME = PowerClass.getSimpleName();
        this.POWER_ID = ModHelper.makeId(CLASS_NAME);
        PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
        String NAME = powerStrings.NAME;

        this.DESCRIPTIONS = powerStrings.DESCRIPTIONS;
        this.name = NAME;
        this.ID = POWER_ID;
        this.owner = owner;
        this.type = PowerType.BUFF;
        this.amount = amount;

        String path128 = ModHelper.makeFileName(PATH_IMG_POWERS, CLASS_NAME, "84", EXTENSION_PNG);
        String path48 = ModHelper.makeFileName(PATH_IMG_POWERS, CLASS_NAME, "32", EXTENSION_PNG);
        this.region128 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path128), 0, 0, 84, 84);
        this.region48 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path48), 0, 0, 32, 32);

        this.updateDescription();
    }

    @Override
    public void atEndOfRound() {
        if (this.amount != -1) {
            AbstractDungeon.actionManager.addToBottom(new ReducePowerAction(this.owner, this.owner, this, 1));
        }

    }
}
